<?php
namespace App\Http\Controllers\ShopApi\V1\CollectMoney;

use App\Http\Controllers\ShopApiController;
use App\Http\Controllers\Business\Shop\V1\CollectMoney\CollectMoney;
use App\Http\Controllers\Business\Common\Common;
use Log;

class CollectMoneyController extends ShopApiController
{
    //收款
    public function collectMoney() {
        $shopUserId = $this->shopUserId;
        $shopId = $this->request->get('shopid');
        $money = $this->request->get('money');
        $payCode = $this->request->get('paycode');
        if($this->request->has('type')) {
            $type = $this->request->get('type');
        } else {
            $type = '';
        }
        if(date('Y-m-d') < '2017-03-01') {
            //老版本的
            $result = CollectMoney::collectMoney($shopUserId, $shopId, $money,$payCode, $type);
        } else {
            //新版本
            $userId = '';
            $result = Common::collectMoney($shopId,$money, 'shop', $userId, $payCode, $shopUserId,$type);
        }
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        $data = isset($result['data']) ? $result['data']:[];
        return $this->responseSuccessData($data);
    }
    //是否可以收款
    public function isCollectMoney() {
        $shopId = $this->request->get('shopid');
        $result = CollectMoney::isCollectMoney($shopId);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        return $this->responseSuccessMessage($result['message']);
    }
}